package com.ruike.alisurface.services;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.CountDownTimer;

import com.ruike.alisurface.BuildConfig;
import com.ruike.alisurface.utils.APPUtils;
import com.voodoo.lib_utils.L;

/**
 * Author: voodoo
 * CreateDate: 2020/04/30 030 09:15 上午
 * Description: 系统开机广播接收
 */
public class DeviceRestartReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context mContext, Intent intent) {
        // 开机广播
        if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
            L.i("机器开机启动完成，即将打开 " + BuildConfig.APPLICATION_ID + " 版本号：" + BuildConfig.VERSION_CODE);
            new CountDownTimer(10* 1000, 10000) {

                @Override
                public void onTick(long l) {

                }

                @Override
                public void onFinish() {
                    int uid = APPUtils.getPackageUid(mContext.getApplicationContext(), BuildConfig.APPLICATION_ID);
                    if (uid > 0) {
                        if (!APPUtils.isAppRunning(mContext.getApplicationContext(), BuildConfig.APPLICATION_ID)) {
                            L.i("主程序未运行  延时时间 5 秒后启动 " + BuildConfig.APPLICATION_ID);
                            APPUtils.openPackage(mContext,mContext.getPackageName());
                        }
                    }
                }
            }.start();
        }
    }
}

